package org.applet.game.app.rpg.resource;

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Arrays;

import org.applet.game.framework.util.ImageLoader;

public class MagicResource {

	public static BufferedImage getMagicTitle(int magicIndex)
	{
		return ImageLoader.loadImage("image/magic/"+magicIndex+"/0.png");
	}
	
	public static BufferedImage[] loadMagicActions(int magicIndex)
	{
		String path = "image/magic/"+magicIndex+"/";
		File dir = new File(path);
		if(dir.isDirectory())
		{
			String[] fileList = dir.list();
			Arrays.sort(fileList);
			BufferedImage[] imgs = new BufferedImage[fileList.length-1];
			int index = 0;
			for(String name:fileList)
			{
				if(name.equals("0.png"))
					continue;
				imgs[index++] = ImageLoader.loadImage(path+name);
			}
			return imgs;
		}
		return null;
	}
	
	public static int getTotalMagicCount()
	{
		File dir = new File("image/magic");
		if(dir.isDirectory())
		{
			return dir.list().length;
		}
		return 0;
	}
	
	public static BufferedImage[] getMagicTitles()
	{
//		ArrayList<BufferedImage> titles = new ArrayList<BufferedImage>();
//		File dir = new File("image/magic");
//		if(dir.isDirectory())
//		{
//			for(File magic:dir.listFiles())
//			{
//				titles.add(ImageLoader.loadImage(magic.getPath()+"/0.png"));
//			}
//		}
		BufferedImage[] title = new BufferedImage[getTotalMagicCount()];
		for(int i=0;i<title.length;i++)
		{
			title[i] = getMagicTitle(i);
		}
		//titles.toArray(title);
		return title;
	}
}
